package assignment.ton.gui.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import assignment.ton.def.Action;
import assignment.ton.def.Parameter;
import assignment.ton.def.Class;
import assignment.ton.gui.AddParameter;
import assignment.ton.gui.ClassFrame;
import assignment.ton.gui.CodeEditorFrame;
import assignment.ton.gui.MainFrame;
/**
 * The action listener for class frame
 * @author Tim
 */
public class ClassFrameActionListener implements ActionListener{
	private ClassFrame classFrame;
	private Class theClass;
	private MainFrame mainFrame;
	private AddParameter p;
	public ClassFrameActionListener(ClassFrame cF, Class c, MainFrame mF){
		classFrame = cF;
		theClass = c;
		mainFrame = mF;
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		String actionCommand = e.getActionCommand();
		if(actionCommand.equals("Add")){
			mainFrame.setAction(Action.ADDCONSTRUCTOR);
			Parameter param = new Parameter(null, null, false);
			p = new AddParameter(theClass, param, mainFrame, classFrame); 	//Create a new parameter entry dialogue.
			p.setVisible(true);										//Make the dialogue visible
		}else if(actionCommand.equals("Delete")){
			classFrame.deleteConstructorItem();
		}else if(actionCommand.equals("Submit")){
			classFrame.submit();
		}else if(actionCommand.equals("Cancel")){
			//do cancel command
			cancel();
		}else if(actionCommand.equals("Edit Extra Code")){
			mainFrame.setAction(Action.EDITCODE);
			CodeEditorFrame cF = new CodeEditorFrame(mainFrame, theClass, null);
			cF.setVisible(true);
		}
		mainFrame.getDrawPanel().repaint();
	}
	public void cancel(){
		if(p!=null){ p.dispose(); }
		classFrame.cancel();
	}

}
